package com.antoco.controlcenter.model.main;

import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;

import com.antoco.controlcenter.R;
import com.antoco.controlcenter.model.data.ConstructionActivity;
import com.antoco.controlcenter.model.video.activity.ControlActivity;
import com.antoco.controlcenter.model.gl.OpenGLActivity;
import com.antoco.controlcenter.base.BaseFragmentActivity;
import com.antoco.controlcenter.manager.ActivityStackManager;
import com.antoco.controlcenter.utils.ToastUtils;

import butterknife.OnClick;

public class MainActivity extends BaseFragmentActivity {
    private long clickTime = 0;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initBundleData() {

    }

    @Override
    protected void initView() {
    }

    @Override
    protected void initData() {

    }


    @OnClick({R.id.btn_control, R.id.btn_exit, R.id.btn_product, R.id.data_tv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_control:
                Intent in = new Intent(MainActivity.this, ControlActivity.class);
                startActivity(in);
                break;
            case R.id.btn_exit:
                ActivityStackManager.getManager().exitApp(mContext);
                break;
            case R.id.btn_product:
                Intent ins = new Intent(MainActivity.this, OpenGLActivity.class);
                startActivity(ins);
                break;
            case R.id.data_tv:
                startActivity(new Intent(MainActivity.this, ConstructionActivity.class));
                break;
        }
    }

    @Override
    public void onBackPressed() {
        exit();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // 是否触发按键为back键
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            onBackPressed();
            return true;
        } else {
            // 如果不是back键正常响应
            return super.onKeyDown(keyCode, event);
        }
    }

    private void exit() {
        if ((System.currentTimeMillis() - clickTime) > 2000) {
            ToastUtils.showToast(this, getResources().getString(R.string.home_exits));
            clickTime = System.currentTimeMillis();
        } else {
            ActivityStackManager.getManager().exitApp(mContext);
        }
    }
}